const _ = require('lodash')
const NormalFactory = require('./NormalFactory')

const CreateBundleList = function(force){
	if(CreateBundleList.cache){
		return CreateBundleList.cache
	}

	let result
	const moduleGroup = modules => {

		if(modules.length <= 0) return []

		const groupMap = {}
		modules.forEach(m => {
			if(groupMap[m.bundleName]){
				groupMap[m.bundleName].push(m)
			}else{
				groupMap[m.bundleName] = [m]
			}
		})

		return Object.values(groupMap)
	}


	const normalModules = NormalFactory.call(this, force)
	CreateBundleList.cache = result = moduleGroup(normalModules)
	return result
}


module.exports = CreateBundleList